/**
  * tips特效汇总
  * TipsUtils.showTipsDownToUp()
  */

module TipsUtils {

    //从下到上弹出
    export function showTipsDownToUp(str: string = "", isWarning: boolean = false): void {
        if(str == ""){
            return;
        }
        // 去掉之前的内容
        if(TipsUtils.tipsView){
            egret.Tween.removeTweens(TipsUtils.tipsView);
            if(TipsUtils.tipsView.parent){
                TipsUtils.tipsView.parent.removeChild(TipsUtils.tipsView);
            }
            TipsUtils.tipsView = null;
        }
        
        let height = 80;
        var continer = new egret.DisplayObjectContainer();
        continer.height = height;
        var effectTips = new egret.TextField();
        
        effectTips.size = 30;
        //effectTips.fontFamily = "微软雅黑";
        // effectTips.y = GameConfig.curHeight()/2;
        // effectTips.alpha = 0;
        //effectTips.bold = true;
        if (isWarning) {
            effectTips.textColor = GameConfig.TextColors.red;
        } else {
            effectTips.textColor = GameConfig.TextColors.white;
        }
        effectTips.text = str;
        continer.width = effectTips.width + 82;

        var bg=new egret.Shape();
        bg.graphics.beginFill(0x000000,0.5);
        bg.graphics.drawRoundRect(0,0,continer.width,height,10,10);
        bg.graphics.endFill();

        effectTips.x = (continer.width-effectTips.width)/2;
        effectTips.y = (height-effectTips.height)/2;
        

        continer.addChild(bg);
        continer.addChild(effectTips);
        
        continer.x=(GameConfig.stageWidth-continer.width)/2;
        continer.y=(GameConfig.stageHeight-continer.height)/2;

        if (!egret.MainContext.instance.stage.contains(continer)) {
            egret.MainContext.instance.stage.addChild(continer);
        }
        TipsUtils.tipsView = continer;
        egret.Tween.get(continer).wait(1500).call(() => {
            if (egret.MainContext.instance.stage.contains(continer)) {
                egret.MainContext.instance.stage.removeChild(continer);
            }
            if(TipsUtils.tipsView){
                TipsUtils.tipsView = null;
            }
        });
    }
    export let tipsView:egret.DisplayObjectContainer;
    //从左至右 或者 从右至左
    export function showTipsLeftOrRight(str: string = "", isWarning: boolean = false, isFromeLeft: boolean = true): void {
        
        if(str == ""){
            return;
        }
        var effectTips = new egret.TextField();
        effectTips.size = 24;
        effectTips.y = GameConfig.stageHeight / 2;
        if (isWarning) {
            effectTips.textColor = GameConfig.TextColors.red;
        } else {
            effectTips.textColor = GameConfig.TextColors.green;
        }
        effectTips.alpha = 0;

        effectTips.text = str;
        effectTips.strokeColor = 0x000000;
        if (isFromeLeft) {
            effectTips.x = - effectTips.width;
        } else {
            effectTips.x = GameConfig.stageWidth;
        }
        effectTips.stroke = 2;
        effectTips.bold = true;
        effectTips.textAlign = egret.HorizontalAlign.CENTER;

        if (!egret.MainContext.instance.stage.contains(effectTips)) {
            egret.MainContext.instance.stage.addChild(effectTips);
        }

        if (isFromeLeft) {
            egret.Tween.get(effectTips).to({ x: GameConfig.stageWidth / 2 - effectTips.width / 2 - 50, alpha: 1 }, 300, egret.Ease.sineInOut);
        } else {
            egret.Tween.get(effectTips).to({ x: GameConfig.stageWidth / 2 - effectTips.width / 2 + 50, alpha: 1 }, 300, egret.Ease.sineInOut);
        }

        egret.setTimeout(function () {
            if (isFromeLeft) {
                egret.Tween.get(effectTips).to({ x: effectTips.x + 100 }, 500);
            } else {
                egret.Tween.get(effectTips).to({ x: effectTips.x - 100 }, 500);
            }
        }, this, 300);

        egret.setTimeout(function () {
            if (isFromeLeft) {
                egret.Tween.get(effectTips).to({ x: GameConfig.stageWidth }, 300, egret.Ease.sineIn);
            } else {
                egret.Tween.get(effectTips).to({ x: -effectTips.width }, 300, egret.Ease.sineIn);
            }
        }, this, 800);

        egret.setTimeout(function () {
            if (egret.MainContext.instance.stage.contains(effectTips)) {
                egret.MainContext.instance.stage.removeChild(effectTips);
                effectTips = null;
            }
        }, this, 1100);

    }

    //从里到外
    export function showTipsFromCenter(str: string = "", isWarning: boolean = false): void {
        if(str == ""){
            return;
        }
        var effectTips = new egret.TextField();

        effectTips.size = 24;
        effectTips.y = GameConfig.stageHeight / 2;
        if (isWarning) {
            effectTips.textColor = GameConfig.TextColors.red;
        } else {
            effectTips.textColor = GameConfig.TextColors.green;
        }
        effectTips.alpha = 0;

        effectTips.text = str;
        effectTips.strokeColor = 0x000000;
        effectTips.x = GameConfig.stageWidth / 2;
        effectTips.stroke = 2;
        effectTips.bold = true;
        effectTips.textAlign = egret.HorizontalAlign.CENTER;
        effectTips.anchorOffsetX = effectTips.width / 2;
        effectTips.anchorOffsetY = effectTips.height / 2;
        effectTips.scaleX = 0;
        effectTips.scaleY = 0;

        if (!egret.MainContext.instance.stage.contains(effectTips)) {
            egret.MainContext.instance.stage.addChild(effectTips);
        }

        var onComplete2: Function = function () {
            if (egret.MainContext.instance.stage.contains(effectTips)) {
                egret.MainContext.instance.stage.removeChild(effectTips);
                effectTips = null;
            }
        };
        egret.Tween.get(effectTips).to({ scaleX: 1, scaleY: 1, alpha: 1 }, 200);
        egret.setTimeout(function () {
            egret.Tween.get(effectTips).to({ alpha: 0 }, 500).call(onComplete2, this);
        }, this, 1000);

    }

    //从外到里
    export function showTipsBigToSmall(str: string = "", isWarning: boolean = false): void {
        if(str == ""){
            return;
        }
        var effectTips = new egret.TextField();

        effectTips.size = 24;
        effectTips.y = GameConfig.stageHeight / 2;
        if (isWarning) {
            effectTips.textColor = GameConfig.TextColors.red;
        } else {
            effectTips.textColor = GameConfig.TextColors.green;
        }
        effectTips.alpha = 0;

        effectTips.text = str;
        effectTips.strokeColor = 0x000000;
        effectTips.x = GameConfig.stageWidth / 2;
        effectTips.stroke = 2;
        effectTips.bold = true;
        effectTips.textAlign = egret.HorizontalAlign.CENTER;
        effectTips.anchorOffsetX = effectTips.width / 2;
        effectTips.anchorOffsetY = effectTips.height / 2;
        effectTips.scaleX = 4;
        effectTips.scaleY = 4;

        if (!egret.MainContext.instance.stage.contains(effectTips)) {
            egret.MainContext.instance.stage.addChild(effectTips);
        }

        var onComplete2: Function = function () {
            if (egret.MainContext.instance.stage.contains(effectTips)) {
                egret.MainContext.instance.stage.removeChild(effectTips);
                effectTips = null;
            }
        };
        egret.Tween.get(effectTips).to({ scaleX: 1, scaleY: 1, alpha: 1 }, 200);
        egret.setTimeout(function () {
            egret.Tween.get(effectTips).to({ alpha: 0 }, 500).call(onComplete2, this);
        }, this, 1000);

    }

}